﻿using miniQQ_Template.Models;
using miniQQ_Template.ViewModel;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace miniQQ_Template.Views
{
    /// <summary>
    /// MainView.xaml 的交互逻辑
    /// </summary>
    public partial class MainView : UserControl
    {
        public MainView()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            (this.DataContext as SettingViewModel).EnabledGroup.Add(GrpTB.Text);
            FileHelper.TryWrite(BaseConfig.FileName,JsonConvert.SerializeObject(Models.Manager.Config));
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            (this.DataContext as SettingViewModel).QQRobots.Add(RbtTB.Text);
            FileHelper.TryWrite(BaseConfig.FileName, JsonConvert.SerializeObject(Models.Manager.Config));
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            (this.DataContext as SettingViewModel).OperatorsQQ.Add(OpTB.Text);
            FileHelper.TryWrite(BaseConfig.FileName, JsonConvert.SerializeObject(Models.Manager.Config));
        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            if (GrpLB.SelectedIndex >= 0)
            {
                (this.DataContext as SettingViewModel).EnabledGroup.RemoveAt(GrpLB.SelectedIndex);
            }
        }

        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            if (GrpLB.SelectedIndex >= 0)
            {
                (this.DataContext as SettingViewModel).QQRobots.RemoveAt(GrpLB.SelectedIndex);
            }
        }

        private void Button_Click_5(object sender, RoutedEventArgs e)
        {
            if (GrpLB.SelectedIndex >= 0)
            {
                (this.DataContext as SettingViewModel).OperatorsQQ.RemoveAt(GrpLB.SelectedIndex);
            }
        }

        private void Button_Click_6(object sender, RoutedEventArgs e)
        {
            Models.Manager.Config.Refresh();
        }
    }
}
